<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
      
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code" label="供应商编码">
          <a-input placeholder="请输入供应商编码" v-model="model.code" />
        </a-form-model-item>

        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name" label="供应商名称">
          <a-input placeholder="请输入供应商名称" v-model="model.name" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workerCount" label="使用次数">
          <a-input-number v-model="model.workerCount"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="position" label="省/市/区（县）">
          <a-input placeholder="请输入省/市/区（县）" v-model="model.position" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address" label="详细地址">
          <a-input placeholder="请输入详细地址" v-model="model.address" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contact" label="联系人">
          <a-input placeholder="请输入联系人" v-model="model.contact" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mobilePhone" label="联系方式">
          <a-input placeholder="请输入联系方式" v-model="model.mobilePhone" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplierLabel" label="供应商标签">
          <a-input placeholder="请输入供应商标签" v-model="model.supplierLabel" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mainLine" label="主要产线">
          <a-input placeholder="请输入主要产线" v-model="model.mainLine" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mainSpeed" label="主要产能">
          <a-input placeholder="请输入主要产能" v-model="model.mainSpeed" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mainSupplier" label="主要供应客户">
          <a-input placeholder="请输入主要供应客户" v-model="model.mainSupplier" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accessProduct" label="准入产品">
          <a-input placeholder="请输入准入产品" v-model="model.accessProduct" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="registerSource" label="供应商来源">
          <a-input placeholder="请输入供应商来源" v-model="model.registerSource" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isNew" label="是否新客户（0：是；1：否）">
          <a-input placeholder="请输入是否新客户（0：是；1：否）" v-model="model.isNew" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isInspect" label="是否实地考察（0：是；1：否）">
          <a-input placeholder="请输入是否实地考察（0：是；1：否）" v-model="model.isInspect" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="inspectComment" label="考察意见">
          <a-input placeholder="请输入考察意见" v-model="model.inspectComment" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="evaluateLevel" label="评价级别（A/B/C/D）">
          <a-input placeholder="请输入评价级别（A/B/C/D）" v-model="model.evaluateLevel" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isComplete" label="资质是否完备（0：是；1：否">
          <a-input placeholder="请输入资质是否完备（0：是；1：否" v-model="model.isComplete" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isExceedTime" label="资质是否过期（0：是；1：否）">
          <a-input placeholder="请输入资质是否过期（0：是；1：否）" v-model="model.isExceedTime" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="state" label="状态（0：信息录入；1：审批通过；2：审批未通过；3：黑名单）">
          <a-input placeholder="请输入状态（0：信息录入；1：审批通过；2：审批未通过；3：黑名单）" v-model="model.state" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="approvalDate" label="审批通过时间">
          <a-date-picker showTime valueFormat='YYYY-MM-DD HH:mm:ss' v-model="model.approvalDate" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="noPassReason" label="审批未通过原因">
          <a-input placeholder="请输入审批未通过原因" v-model="model.noPassReason" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delFlag" label="删除标识（0未删除|1已删除）">
          <a-input placeholder="请输入删除标识（0未删除|1已删除）" v-model="model.delFlag" />
        </a-form-model-item>
		
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import moment from "moment"

  export default {
    name: "MdmSupplierModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        delFlag:[{ required: true, message: '请输入删除标识（0未删除|1已删除）!' }],
        },
        url: {
          add: "/supplier/mdmSupplier/add",
          edit: "/supplier/mdmSupplier/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        //初始化默认值
        this.edit({});
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
         this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false;
          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>